package com.dslcode.cloud.common.enums;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * Created by dongsilin on 2017/9/30.
 * enum json 序列化
 */
public class EnumJsonSerializer extends JsonSerializer<IntEnum> {

    @Override
    public void serialize(IntEnum e, JsonGenerator generator, SerializerProvider provider) throws IOException {
        if (null == e) return;
        generator.writeStartObject();
        generator.writeFieldName("id");
        generator.writeNumber(e.getIntValue());
        generator.writeFieldName("name");
        generator.writeString(e.getName());
        generator.writeEndObject();
    }

}
